var $table = $('#table');
var $tablez1 = $('#table_z1');
var $tablez2 = $('#table_z2');
var $tablez3 = $('#table_z3');
var $caddbtn = $("#cadd");
var $queryBtn = $('#queryBtn');
var $cupdz = $('#cupdz');
var $cedit = $('#cedit');
var $cdel = $('#cdel');
var $cimp= $('#cimp');

var $z1addbtn = $("#z1add");
var $z1edit= $('#z1edit');
var $z1del = $('#z1del');
var $z1imp= $('#z1imp');

var $z2addbtn = $("#z2add");
var $z2edit= $('#z2edit');
var $z2del = $('#z2del');
var $z2imp= $('#z2imp');

var $z3addbtn = $("#z3add");
var $z3edit= $('#z3edit');
var $z3del = $('#z3del');
var $z3imp= $('#z3imp');



var uploader;
var uploader_e;
var $list;
var $list_e;
var $cexp= $('#cexp');
var $z1cexp= $('#z1cexp');
var $z2cexp= $('#z2cexp');
var $z3cexp= $('#z3cexp');
var cmd = function(name, data) {
    if(rapid.isJson(data)) {
        return name + rapid.parseString(data);
    }

    return name + data;
};
var element,__WS_URL;

$('#layui').on('hide.bs.modal', function () {

    ws.close();

})

var ws;
//连接到websocket


element = layui.element;

$("#closed1").click(function () {
    $("#shuliang").val(1);
});




function dyewm(src){
    var LODOP = getLodop();
    console.log(LODOP)
    var maxPrint = 5;
    if(typeof (LODOP) != "undefined" && LODOP.webskt ){
        if( LODOP.webskt.readyState == 1){
            if (!rapid.isEmpty(src) && !rapid.isEmpty(src)) {




                var _html = [];
                _html.push("<div style='width: 100%;'><div style='font-size: 20px;font-weight: bolder;text-align: center;padding-top: 2px;'><img style=' position:absolute;clip:rect(0px,150px,120px,0px); ' width='150px' height='140px' src='"+src+"'></img></div>");

                _html.push("</div>");
                if (typeof (LODOP) != "undefined" && LODOP.webskt && LODOP.webskt.readyState == 1) {
                    LODOP.SET_PRINT_STYLE("FontSize", 12);
                    LODOP.SET_PRINT_STYLE("Bold", 1);
                    LODOP.SET_PRINT_PAGESIZE(1,"60mm","40mm","A01");
                    LODOP.ADD_PRINT_HTM("0.2cm", "0.7cm", "RightMargin:0cm", "BottomMargin:0mm", _html.join(""));
                    LODOP.NewPage();
                }
                LODOP.PREVIEW();  //预览
                rapid.success();
            } else {

                rapid.fail("没有数据，请重新选择！");
            }}else{
            rapid.fail("打印插件未启动，请启动Lodop打印插件。！");
        }
    }else{
        rapid.confirm("打印驱动未安装，是否下载安装打印驱动？", function (yes) {
            if (yes) {
                window.open("/lib/ui/js/plugins/install_lodop64.exe");
            }
        })
    }
}

function zppt(value) {


    $("#myzmps").modal();

    if(value=='null'){
        $('#zp').attr('src',"/files/1.jpg");
    }else{
        $('#zp').attr('src',value);
    }

};

function zz(row) {

    $("#cid1").val(row);
    $("#myModal1").modal();

};




function sc(row,status) {
    if(status=='Y'){
        $("#cid").val(row);
        $("#myModal").modal();
    }else{
        rapid.info("商品已经下架!");
    }

};

function zpone(value) {


    rapid.post({
        url: "/sysadmin/dbcontact/getOneZp",
        data: "cid=" +value,
        success: function (result) {
            $("#myzmps").modal();
            if(result=='null'){
                $('#zp').attr('src',"/files/1.png");
            }else{
                $('#zp').attr('src',result);
            }



        }
    });

};

$(function () {

    var config = {
        decrementButton: "<b>-</b>", // 按钮文本
        incrementButton: "<b>+</b>", // ..
        groupClass: "sm", // 输入组的CSS类
        buttonsClass: "btn-outline-secondary",
        buttonsWidth: "2.5rem",
        textAlign: "center",
        autoDelay: 500, // 自动值更改前保持 ms
        autoInterval: 100, // 自动值更改速度
        boostThreshold: 10, // boost after these steps
        boostMultiplier: "auto" // you can also set a constant number as multiplier
    }

    $("input[type='number']").inputSpinner(config);

    $(".input-group-append").css({"float":"left"});
    $(".input-group-prepend").css({"float":"left"})
    $(".input-group").css({"width":"80%"})
    $('.form-control-chosen').chosen({
        allow_single_deselect: true,
        width: '100%'
    });

    $cexp.click(function () {

        var searchtext = $("#searchString_id").val();
        var searchvalcorid = $("#searchString_corid").val();
        var searchvaltelid=$("#searchString_telid").val();
        var searchvalproid=$("#searchString_proid").val();
        window.location.href ="/sysadmin/dbcontact/exportContact?searchval=" + searchtext+"&searchvalcorid="+searchvalcorid+"&ph="+searchvaltelid+"&unit="+searchvalproid;

    });



    $list = $("#thelist");


    $list_e = $("#thelist_e");


    var $btn = $("#ctlBtn");   //开始上传

    var $btn_e = $("#ctlBtn_e");   //开始上传


    __bindRdetailformuploadinit = function () {
        // 初始化Web Uploader

        uploader = WebUploader.create({

            // 选完文件后，是否自动上传。
            auto: false,

            // swf文件路径
            swf: '/script/pc/sysmgt/dbcontact/Uploader.swf',

            // 文件接收服务端。
            server: '/comm/api/webUpload',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker',

            fileSingleSizeLimit: 15 * 1024 * 1024,   //设定单个文件大小
            //限制只能上传一个文件
            //fileNumLimit: 1,

            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });


        uploader_e = WebUploader.create({

            // 选完文件后，是否自动上传。
            auto: false,

            // swf文件路径
            swf: '/script/pc/sysmgt/dbcontact/Uploader.swf',

            // 文件接收服务端。
            server: '/comm/api/webUpload',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker_e',

            fileSingleSizeLimit: 15 * 1024 * 1024,   //设定单个文件大小
            //限制只能上传一个文件
            //fileNumLimit: 1,

            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });

        //点击上传按钮触发事件
        $btn.click(function () {


            uploader.upload();


        });
        //点击上传按钮触发事件
        $btn_e.click(function () {


            uploader_e.upload();


        });

        // 当有文件添加进来的时候
        uploader.on('fileQueued', function (file) {

            for (var i = 0; i < uploader.getFiles().length-1; i++) {
                // 将图片从上传序列移除\

                // uploader.removeFile(uploader.getFiles()[i]);
                uploader.removeFile(uploader.getFiles()[i], true);
                delete uploader.getFiles()[i];
                // 将图片从缩略图容器移除
                var $li = $('#' + uploader.getFiles()[i].id);
                $li.off().remove();
            }

            $list.append('<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>');


        });


        // 当有文件添加进来的时候
        uploader_e.on('fileQueued', function (file) {

            for (var i = 0; i < uploader_e.getFiles().length-1; i++) {

                uploader_e.removeFile(uploader.getFiles()[i], true);
                delete uploader_e.getFiles()[i];
                // 将图片从缩略图容器移除
                var $li = $('#' + uploader_e.getFiles()[i].id);
                $li.off().remove();
            }



            $list_e.append('<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>');
        });

// 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo($li).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css('width', percentage * 100 + '%');
        });


        uploader_e.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo($li).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css('width', percentage * 100 + '%');
        });

        uploader.on('uploadSuccess', function (file,response) {

            $("#hideFileName").val(response.data)

            $('#' + file.id).find('p.state').text('已上传');
        });

        uploader_e.on('uploadSuccess', function (file,response) {


            $("#hideFileName_e").val(response.data)
            $('#' + file.id).find('p.state').text('已上传');
        });
        uploader_e.on('uploadError', function (file) {
            $('#' + file.id).find('p.state').text('上传出错');
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('p.state').text('上传出错');
        });

        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').fadeOut();
        });

        uploader_e.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').fadeOut();
        });
    }


    function tablepak(table){

        table.bootstrapTable('refresh', {query: {pageIndex: 1,pageSize:10}});

    }


  function hiddenfind(){
        var hiddenvalue=$("hidden_value").val();
        if(hiddenvalue!=null|hiddenvalue!=''){
            var searchtext = $("#searchString_id").val();
            var searchvalcorid = $("#searchString_corid").val();
            var searchvaltelid=$("#searchString_telid").val();
            var searchvalproid=$("#searchString_proid").val();
            $table.bootstrapTable('refresh', {query: {searchval: searchtext,searchvalcorid:searchvalcorid,ph:searchvaltelid,unit:searchvalproid}});


        }
    }

    $caddbtn.click(function () {
        $("#myModalz").modal();
        $("#attrib_05").prop("disabled","");
        $("#attrib_12").prop("disabled","");
        $("#attrib_34").prop("disabled","");
        $("#pic").prop("style","display: ");
    });

    $cedit.click(function () {


        var info = $table.bootstrapTable('getSelections');
        $("#pic_e").prop("style","display: ");
        if(info.length!=1){
            rapid.info("请选择一行编辑!");
        }else {

                rapid.post({
                    url: "/sysadmin/commodity/getpl",
                    data: "cid=" + info[0].conflict_id,
                    success: function (result) {
                        $("#attrib_05_e").empty();

                        $("#attrib_12_e").empty();
                        $("#attrib_34_e").empty();

                        $("#myModalzedit").modal();
                        $("#conflict_idz_e").val(result.conflict_id);
                        $("#cidz_e").val(result.row_id);
                        $("#attrib_05_e").append(result.attrib_05);

                        $("#attrib_12_e").append(result.attrib_12);
                        var kcl=result.attrib_17;
                        console.log(kcl);
                        if(rapid.isEmpty(kcl) || kcl=='null' || isNaN(kcl)){
                                kcl=0;
                        }
                        $("#attrib_17_e").val(kcl);
                        $("#attrib_19_e").val(result.attrib_19);
                        $("#attrib_20_e").val(result.attrib_20);
                        $("#hideFileName_e").val(result.attrib_45);

                        $("#attrib_08_e option[value='" + result.attrib_08 + "']").prop("selected", true);
                        $("#attrib_23_e").val(result.attrib_23);

                        $("#attrib_34_e").append(result.attrib_34);
                      

                    }
                });

        }
    });

    $cupdz.click(function () {



            rapid.post({
                url: "/sysadmin/commodity/upjjdz",
               /* data: "cid=" + info[0].conflict_id,*/
                success: function (result) {



                }
            });


    });

    $z1edit.click(function () {
        var info1 = $table.bootstrapTable('getSelections');
        var info = $tablez1.bootstrapTable('getSelections');


        if(info1.length!=1 || info.length!=1){
            rapid.info("请选择一行编辑!");
        }else {
            rapid.post({
                url: "/sysadmin/commodity/getpz",
                data: "cid=" + info[0].conflict_id,
                success: function (result) {
                    $("#attrib_03_z1").empty();

                    $("#splb_z1").empty();
                    $("#attrib_05_z1").empty();
                    $("#attrib_12_z1").empty();
                    $("#attrib_09_z1").empty();
                    $("#attrib_35_z1").empty();
                    $("#attrib_07_z1").empty();
                    $("#attrib_13_z1").empty();
                    $("#attrib_15_z1").empty();
                    $("#attrib_37_z1").empty();
                    $("#attrib_39_z1").empty();
                    $("#attrib_08_z1").empty();
                    $("#attrib_19_z1").empty();
                    $("#attrib_20_z1").empty();

                    $("#myModalz1").modal();
                    $("#conflict_idz1").val(result.conflict_id);

                    $("#attrib_03_z1").append(result.attrib_03);
                    $("#splb_z1").append( result.attrib_34);
                    $("#attrib_05_z1").append(result.attrib_05);
                    $("#attrib_12_z1").append(result.attrib_12);
                    $("#attrib_09_z1").append(result.attrib_09);
                    $("#attrib_58_z1").attr("src",result.attrib_58);
                    $("#attrib_38_z1").val(result.attrib_38);
                    $("#attrib_39_z1").val(result.attrib_39);
                    $("#attrib_19_z1").val(result.attrib_19);
                    $("#attrib_20_z1").val(result.attrib_20);
                    $("#attrib_35_z1").append(result.attrib_35);
                    $("#attrib_51_z1").attr("src",result.attrib_51);
                    $("#attrib_45_z1").attr("src",result.attrib_45);
                    $("#attrib_07_z1").append(result.attrib_07);
                    $("#attrib_13_z1").append(result.attrib_13);
                    $("#attrib_15_z1").append(result.attrib_15);
                    $("#attrib_37_z1").append(changeDateFormat(result.attrib_37));
                    $("#attrib_08_z1").append(result.attrib_08);


                }
            });
        }
    });
    $z3edit.click(function () {
        var info1 = $table.bootstrapTable('getSelections');
        var info = $tablez3.bootstrapTable('getSelections');


        if(info1.length!=1 || info.length!=1){
            rapid.info("请选择一行编辑!");
        }else {
            rapid.post({
                url: "/sysadmin/commodity/getdd",
                data: "cid=" + info[0].conflict_id,
                success: function (result) {
                    $("#attrib_36_z3").empty();
                    $("#splb").empty();
                    $("#pzid").empty();

                    $("#attrib_05_z3").empty();
                    $("#attrib_12_z3").empty();
                    $("#attrib_24_z3").empty();
                    $("#attrib_17_z3").empty();
                    $("#attrib_37_z3").empty();
                    $("#attrib_03_z3").empty();
                    $("#attrib_33_z3").empty();
                    $("#attrib_10_z3").empty();
                    $("#attrib_13_z3").empty();
                    $("#attrib_19_z3").empty();
                    $("#attrib_31_z3").empty();
                    $("#attrib_26_z3").empty();
                    $("#attrib_27_z3").empty();
                    $("#myModalz3").modal();
                    $("#conflict_idz3").val(result.conflict_id);

                    $("#attrib_36_z3").append(result.attrib_36);
                    $("#splb").append( info[0].splb);
                    $("#pzid").append( info[0].pzid);

                    $("#attrib_05_z3").append(result.attrib_05);
                    $("#attrib_12_z3").append(result.attrib_12);
                    $("#attrib_24_z3").append(result.attrib_24);
                    $("#attrib_17_z3").append(result.attrib_17);
                    $("#attrib_37_z3").append(changeDateFormat(result.attrib_37));
                    $("#attrib_03_z3").append(info[0].shrkx);
                    $("#attrib_33_z3").append(result.attrib_33);
                    $("#attrib_10_z3").append(result.attrib_10);
                    $("#attrib_13_z3").append(result.attrib_13);
                    $("#attrib_19_z3").append(result.attrib_19);
                    $("#attrib_31_z3").append(result.attrib_31);
                    $("#attrib_26_z3").append(changeDateFormat(result.attrib_26));
                    $("#attrib_27_z3").append(changeDateFormat(result.attrib_27));

                    $("#attrib_08_z3 option[value='" + result.attrib_08 + "']").prop("selected", true);

                    $("#attrib_09_z3 option[value='" + result.attrib_09 + "']").prop("selected", true);


                }
            });
        }
    });

    $queryBtn.click(function () {
        var searchval = $("#searchString_id").val();
        var searchvalcorid = $("#searchString_corid").val();
        var money=$("#searchString_money").val();
        var pltype=$("#searchString_type").val();
        var status=$("#searchString_status").val();
        $table.bootstrapTable('refresh', {query: {searchval: searchval,searchvalcorid:searchvalcorid,money:money,pltype:pltype,status:status}});

        $tablez1.bootstrapTable('destroy');  // 销毁原表格
        $tablez2.bootstrapTable('destroy');  // 销毁原表格
        $tablez3.bootstrapTable('destroy');  // 销毁原表格

        inittabl1();
        inittabl2();
        inittabl3();

    });


    $('#myModal').on('hidden.bs.modal', function () {
        $("#contactform").data('bootstrapValidator').destroy();
        $('#contactform').data('bootstrapValidator', null);

        $("#conflict_id").val("");
        formValidator($("#contactform"));
        $("#contactform")[0].reset();
    })

    $('#myModal1').on('hidden.bs.modal', function () {
        $("#contactform1").data('bootstrapValidator').destroy();
        $('#contactform1').data('bootstrapValidator', null);
        $("#conflict_id_z1").val("");
        $("#rowidz1").val("");
        formValidator1($("#contactform1"));
        $("#contactform1")[0].reset();
    })

    $('#myModalz').on('hidden.bs.modal', function () {
        $("#contactformz").data('bootstrapValidator').destroy();
        $('#contactformz').data('bootstrapValidator', null);
        formValidator2($("#contactformz"));

        $("#hideFileName").val("");
        for (var i = 0; i < uploader.getFiles().length; i++) {

            uploader.removeFile(uploader.getFiles()[i], true);
            delete uploader.getFiles()[i];
            // 将图片从缩略图容器移除
            var $li = $('#' + uploader.getFiles()[i].id);
            $li.off().remove();

        }
        uploader.reset();
        $("#contactformz")[0].reset();
    })

    $('#myModalz3').on('hidden.bs.modal', function () {
        $("#contactformz3").data('bootstrapValidator').destroy();
        $('#contactformz3').data('bootstrapValidator', null);
        formValidator3($("#contactformz3"));
        $("#contactformz3")[0].reset();
    })
    $('#myModalz1').on('hidden.bs.modal', function () {
        $("#contactformz1").data('bootstrapValidator').destroy();
        $('#contactformz1').data('bootstrapValidator', null);
        formValidator1($("#contactformz1"));
        $("#contactformz1")[0].reset();

    })


    $('#myModalzedit').on('hidden.bs.modal', function () {
        $("#contactformz_e").data('bootstrapValidator').destroy();
        $('#contactformz_e').data('bootstrapValidator', null);
        formValidator2_e($("#contactformz_e"));
        $("#hideFileName_e").val("");
        for (var i = 0; i < uploader_e.getFiles().length; i++) {

            uploader_e.removeFile(uploader_e.getFiles()[i], true);
            delete uploader_e.getFiles()[i];
            // 将图片从缩略图容器移除
            var $li = $('#' + uploader_e.getFiles()[i].id);
            $li.off().remove();

        }
        uploader_e.reset();
        $("#contactformz_e")[0].reset();
    })

    $('#myModalimp').on('hidden.bs.modal', function () {
        $("#contactformimp").data('bootstrapValidator').destroy();
        $('#contactformimp').data('bootstrapValidator', null);
        formValidatorimp($("#contactformimp"));

        $("#hideFileName").val("");
        for (var i = 0; i < uploader.getFiles().length; i++) {

            uploader.removeFile(uploader.getFiles()[i], true);
            delete uploader.getFiles()[i];
            // 将图片从缩略图容器移除
            var $li = $('#' + uploader.getFiles()[i].id);
            $li.off().remove();

        }
        uploader.reset();


        $("#contactformimp")[0].reset();
    })

    /* 加载时间选择插件 */
    $("#attrib_37").on('hide',function(e) {
        $("#contactform").bootstrapValidator('validate');
        var flag = $("#contactform").data('bootstrapValidator').updateStatus('attrib_37', 'NOT_VALIDATED',null)
            .validateField('attrib_37');


    })

    function formValidator(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_04: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '姓名不能为空'
                        }
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_03: {
                    validators: {
                        notEmpty: {
                            message: '证件号不能为空'
                        }
                    }
                },
                attrib_02: {
                    validators: {
                        notEmpty: {
                            message: '证件类型不能为空'
                        }
                    }
                },
                attrib_37: {
                    validators: {
                        notEmpty: {
                            message: '出生日期不能为空'
                        }

                    }
                }
            }
        })


    }
    function formValidator1(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_02: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '证件类型不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_03: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '证件号码不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }

            }
        })


    }
    function formValidator2(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_34: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '类别不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_05: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '商品名称不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_12: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '规格不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_08: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '是否上架不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_23: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '价格不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }, attrib_19: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '生产产地不能为空'
                        }
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }, attrib_20: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '生产厂商不能为空'
                        }
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }


            }
        })


    }


    function formValidator2_e(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/

                attrib_17: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '数量不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_08: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '是否上架不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                attrib_23: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '价格不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },attrib_19: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '生产产地不能为空'
                        }
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }, attrib_20: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '生产厂商不能为空'
                        }
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }


            }
        })


    }
    function formValidator3(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_08: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '物流可信账户不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }/*,
                attrib_09: {
                    /!*键名username和input name值对应*!/
                    validators: {
                        notEmpty: {
                            /!*非空提示*!/
                            message: '经销商可信账户不能为空'
                        },
//                           stringLength: {/!*长度提示*!/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/!*最后一个没有逗号*!/
                    }
                }*/


            }
        })


    }


    function formValidatorimp(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                umdKey: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '请选择主键'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                updateRule: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '请选择更新规则'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }

            }
        })


    }
    function connect(cid,shuliang){
        if ("WebSocket" in window) {
            $.post('/sysadmin/commodity/getWebsocketUrl',function(data){

                __WS_URL = data.data.url;

                ws = new WebSocket(__WS_URL);

                ws.onopen = function() {
                    console.log("连接成功");

                    if (ws.readyState===1) {

                        ws.send(cmd("SESSIONCMD", {sessionid: data.data.sessionid}));

                    }
                };


                ws.onmessage = function (evt) {
                    //接收服务端的推送信息，改变进度条


                    var data=evt.data;
                    var obj =  eval('(' + data + ')');


                    if( obj.name=='SUCCESS'){

                        rapid.post({
                            url: "/sysadmin/commodity/svaekxpz?cid="+cid+"&shuliang="+shuliang,
                            data: $("#contactform").serialize(),
                            success: function (result) {
                                $("#shuliang").val(1);
                            },
                            fail:function () {
                                close();

                            }

                        });

                    }else if(obj.name=='CLOSE' || obj.name=='LOGOUT' || obj.name=='ERROR'){
                        close();
                    }else{

                        $(".layui-progress-text").css("color","");
                        $(".layui-progress-text").css("color","#fffff");
                        element.progress('executeprogress', obj.data);
                    }


                };
                ws.onclose = function() {
                    // 关闭 websocket
                    console.log("连接已关闭...");
                };
                //服务端返回，任务执行完毕，关闭连接

            });

        }

        else{
            // 浏览器不支持 WebSocket
            alert("您的浏览器不支持 WebSocket!");
        }
    }
//关闭websocket
    function close(){

        ws.close();
        setTimeout(function(){

            $('#layui').modal('hide');
            tablepak($tablez1);

        },1500);


    }




    $("#sava-edit-btn").click(function () {
        $("#contactform").bootstrapValidator('validate');
        var flag = $("#contactform").data('bootstrapValidator').isValid();
        var cid =$("#cid").val();
        var shuliang =$("#shuliang").val();
        if (flag) {

            rapid.confirm("确定要生成吗？", function (yes) {
                if (yes) {
                    $('#myModal').modal('hide');

                    element.progress('executeprogress', '0%');
                    //连接到websocket
                    connect(cid,shuliang);
                    //请求服务端进行执行任务
                    $("#layui").modal({backdrop: 'static', keyboard: false});
                    $(".layui-progress-text").css("color","#0C0C0C");

                }
            });
        }


    })

    $("#sava-edit-btn_z1").click(function () {
        $("#contactform1").bootstrapValidator('validate');
        var flag = $("#contactform1").data('bootstrapValidator').isValid();
        var cid =$("#cid1").val();
        var namedata =$("#kxzh").val();

        if (flag) {

            rapid.confirm("确定要转账吗？", function (yes) {
                if (yes) {
                    $('#myModal1').modal('hide');
                    rapid.post({
                        url: "/sysadmin/commodity/svaezz?cid="+cid+"&namedata="+namedata,
                        data: $("#contactform1").serialize(),
                        success: function (result) {
                            tablepak($tablez1);
                        }
                    });
                }
            });
        }


    })

    $("#sava-edit-btnz").click(function () {
        $("#contactformz").bootstrapValidator('validate');
        var flag = $("#contactformz").data('bootstrapValidator').isValid();
       var filename=  $("#hideFileName").val();
        if (flag) {
            if(filename==''){
                rapid.info("请上传，商品图片！")
            }else {
                rapid.confirm("确定要保存吗？", function (yes) {
                    if (yes) {
                        $('#myModalz').modal('hide');
                        rapid.post({
                            url: "/sysadmin/commodity/savepl",
                            data: $("#contactformz").serialize(),
                            success: function (result) {
                                tablepak($table);
                            }
                        });
                    }
                });
            }
        }


    })


    $("#sava-edit-btnz3").click(function () {
        $("#contactformz3").bootstrapValidator('validate');
        var flag = $("#contactformz3").data('bootstrapValidator').isValid();

        if (flag) {

                rapid.confirm("确定要保存吗？", function (yes) {
                    if (yes) {
                        $('#myModalz3').modal('hide');
                        rapid.post({
                            url: "/sysadmin/commodity/updatedd",
                            data: $("#contactformz3").serialize(),
                            success: function (result) {
                                tablepak($tablez3);
                            }
                        });
                    }
                });
            }



    })

    $("#sava-edit-btnz1").click(function () {
        $("#contactformz1").bootstrapValidator('validate');
        var flag = $("#contactformz1").data('bootstrapValidator').isValid();

        if (flag) {

            rapid.confirm("确定要保存吗？", function (yes) {
                if (yes) {
                    $('#myModalz1').modal('hide');
                    rapid.post({
                        url: "/sysadmin/commodity/updatepz",
                        data: $("#contactformz1").serialize(),
                        success: function (result) {
                            tablepak($tablez1);
                        }
                    });
                }
            });
        }



    })

    $("#sava-edit-btnz_e").click(function () {
        $("#contactformz_e").bootstrapValidator('validate');
        var flag = $("#contactformz_e").data('bootstrapValidator').isValid();
        if (flag) {
            var filename=  $("#hideFileName_e").val();

            if(filename==''){
                rapid.info("请上传，商品图片！")
            }else {
                rapid.confirm("确定要保存吗？", function (yes) {
                    if (yes) {
                        $('#myModalzedit').modal('hide');
                        rapid.post({
                            url: "/sysadmin/commodity/updatepl",
                            data: $("#contactformz_e").serialize(),
                            success: function (result) {
                                tablepak($table);
                            }
                        });
                    }
                });
            }
        }


    })




    function inittabl1(rid) {
        $tablez1.bootstrapTable({
            url:'/sysadmin/commodity/getkltkxpzs',
            idField: 'conflict_id',
            dataType: 'json',
            sidePagination: "server", //服务端处理分页
            queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
            queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的

                if(null != params.multiSort && undefined != params.multiSort){
                    params.sort = params.multiSort.map(item => {
                        return item.sortName;
                    }).join(',');
                    params.order = params.multiSort.map(item => {
                        return item.sortOrder;
                    }).join(',');
                    params.multiSort = null;
                }

                return {//这里的params是table提供的
                    pageIndex: params.pageNumber,//从数据库第几条记录开始
                    pageSize: params.pageSize,//找多少条
                    row_id:rid,
                    sortName: params.sortName,
                    sortOrder: params.sortOrder,
                    sort:params.sort,
                    order:params.order
                }
            },
            responseHandler: function (res) {
                var result = {total: 0, rows: []};

                if (res.recordCount > 0) {
                    result.total = res.recordCount;
                    result.rows = res.list;
                }
                return result;
            },
            sortable: true,
            showMultiSort: true,
            pagination: 'true',  //开启分页
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            singleSelect: true, //单选

            showColumns: true,
            clickToSelect: true,
            showRefresh: true,
            columns: [
                {
                    field: 'check', checkbox: true, formatter: function (value, row, index) {
                        if (row.check == true) {
                            // console.log(row.serverName);
                            //设置选中
                            return {checked: true};
                        }
                    }
                },
                // {field: 'id', title: '编号', sortable: true, align: 'center'},
                // {field: 'pid', title: '所属上级'},

                {field: 'attrib_03', title: '可信凭证ID',width:150,class:'colStyle', align: 'center',sortable : true,formatter: function (value, row, index) {
                        return changeDateFormattokenid(value)
                    }},
                {field: 'attrib_34', title: '类别',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_05', title: '商品名称',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_12', title: '规格',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_19', title: '生产产地',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_20', title: '生产厂商',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_45', title: '商品图片',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='javascript:zppt(\""+value+"\");'  ><img src=\""+value+"\"  width='80px' height='80px' style='text-align: center'/></a>"
                    }},
                {field: 'attrib_09', title: '二维码',width:150,class:'colStyle', align: 'center',sortable : true,formatter: function (value, row, index) {
                        return changeDateFormattokenid(value)
                    }},
                {field: 'attrib_58', title: '二维码图片',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='javascript:zppt(\""+value+"\");'  ><img src=\""+value+"\"  width='80px' height='80px' style='text-align: center'/></a>"
                    }},
                {field: 'attrib_38', title: '标签编码',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_39', title: 'RFID',width:100,class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_35', title: '积分码',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_51', title: '积分码图片',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='javascript:zppt(\""+value+"\");'  ><img src=\""+value+"\"  width='80px' height='80px' style='text-align: center'/></a>"
                    }},
                {field: 'attrib_07', title: '仓库',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_13', title: '流通状态',width:300,class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_15', title: '是否转账',width:300, align: 'center',sortable : true,formatter: function (value, row, index) {
                        if(value=='Y'){
                            return "是";
                        }else{
                            return "否";
                        }

                    }},
                {field: 'attrib_37', title: '生成日期',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {
                        return changeDateFormat1(value)
                    }},
                {field: 'attrib_08', title: '是否销毁',sortable : true,
                    formatter: function (value, row, index) {
                        if (value == 'Y') {

                            //设置选中
                            return "是"
                        }else if(value == 'N'){
                            return "否"
                        }
                    },class:'colStyle', align: 'center'},
                {field: 'attrib_99', title: '链上信息',width:300, align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='/sysadmin/block/transDetail/"+value+"'  target='_blank' >链上信息</a>"
                    }},
                {field: 'conflict_id', title: '转账', align: 'center',
                    formatter: function (value, row, index) {
                        if (row.attrib_15 == 'N') {
                            // console.log(row.serverName);
                            //设置选中

                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xl " href="#" onclick="zz(\'' + value + '\')"><i class="fa fa-rmb"></i>转账</a> ');

                            return actions.join('');

                        }else if(row.attrib_15 == 'Y'){
                            return "已转账"
                        }
                    },class:'colStyle'},   {field: 'conflict_id', title: '打印', align: 'center',
                    formatter: function (value, row, index) {

                            // console.log(row.serverName);
                            //设置选中

                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xl " href="#" onclick="dyewm(\'' + row.attrib_58 + '\')"><i class="fa fa-print"></i>打印</a> ');

                            return actions.join('');


                    },class:'colStyle'}


            ],

            // bootstrap-table-treegrid.js 插件配置 -- start

            //在哪一列展开树形
            treeShowField: 'attrib_02',
            //指定父id列
            parentIdField: 'par_row_id',

            onResetView: function () {

                $tablez1.treegrid({
                    initialState: 'collapsed',// 所有节点都折叠
                    //  initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function () {
                        $tablez1.bootstrapTable('resetWidth');
                    }
                });

                //只展开树形的第一级节点
                $tablez1.treegrid('getRootNodes').treegrid('expand');

            },
            onCheck: function (row) {

                var datas = $tablez1.bootstrapTable('getData');

                // 勾选子类
                selectChilds(datas, row, "conflict_id", "par_row_id", true);

                // 勾选父类
                selectParentChecked(datas, row, "conflict_id", "par_row_id")

                // 刷新数据
                //   $tablez2.bootstrapTable('load', datas);
            },

            onUncheck: function (row) {
                var datas = $tablez1.bootstrapTable('getData');
                selectChilds(datas, row, "conflict_id", "par_row_id", false);
                //   $tablez2.bootstrapTable('load', datas);
            },
            onClickRow: function (row, $element) {
                $tablez1.bootstrapTable('uncheckAll');
                var datas = $tablez1.bootstrapTable('getData');
                row.check = true;
                //   $tablez2.bootstrapTable('load', datas);


            }

            // bootstrap-table-treetreegrid.js 插件配置 -- end
        });

    }

    function changeDateFormat(cellval) {
        var val=cellval+"";

        if( val != '' && val !=null && val !='null' &&  val!='undefined')
        {
            return val.substring(0,10)
        }

    }

    function changeDateFormat1(cellval) {
        var val=cellval+"";

        if( val != '' && val !=null && val !='null' &&  val!='undefined')
        {
            return val.substring(0,19)
        }

    }

    function changeDateFormattokenid(cellval) {
        var val=cellval+"";



        if( val != '' && val !=null && val !='null' &&  val!='undefined'&& val.length>20)
        {

            return val.substring(0,23)+"<br>"+val.substring(23,46)+"<br>"+val.substring(46,val.length);
        }

    }
    function inittabl2(rid) {
        $tablez2.bootstrapTable({
            url:'/sysadmin/commodity/getyxhpzs',
            idField: 'conflict_id',
            dataType: 'json',
            sidePagination: "server", //服务端处理分页
            queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
            queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的


                if(null != params.multiSort && undefined != params.multiSort){
                    params.sort = params.multiSort.map(item => {
                        return item.sortName;
                    }).join(',');
                    params.order = params.multiSort.map(item => {
                        return item.sortOrder;
                    }).join(',');
                    params.multiSort = null;
                }
                return {//这里的params是table提供的
                    pageIndex: params.pageNumber,//从数据库第几条记录开始
                    pageSize: params.pageSize,//找多少条
                    row_id:rid,
                    sortName: params.sortName,
                    sortOrder: params.sortOrder,
                    sort:params.sort,
                    order:params.order
                }
            },
            responseHandler: function (res) {
                var result = {total: 0, rows: []};

                if (res.recordCount > 0) {
                    result.total = res.recordCount;
                    result.rows = res.list;
                }
                return result;
            },
            sortable: true,
            showMultiSort: true,
            pagination: 'true',  //开启分页
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            // singleSelect: true, //单选

            showColumns: true,
            clickToSelect: true,
            showRefresh: true,
            columns: [
               /* {
                    field: 'check', checkbox: true, formatter: function (value, row, index) {
                        if (row.check == true) {
                            // console.log(row.serverName);
                            //设置选中
                            return {checked: true};
                        }
                    }
                },
*/
                {field: 'attrib_03', title: '可信凭证ID',width:150,class:'colStyle', align: 'center',sortable : true,formatter: function (value, row, index) {
                        return changeDateFormattokenid(value)
                    }},
               {field: 'attrib_34', title: '类别',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_05', title: '商品名称',width:300,class:'colStyle', align: 'center',sortable : true},

                {field: 'attrib_12', title: '规格',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_08', title: '是否销毁', align: 'center',sortable : true,
                    formatter: function (value, row, index) {
                        if (value == 'Y') {
                            // console.log(row.serverName);
                            //设置选中
                            return "是"
                        }else if(value == 'N'){
                            return "否"
                        }
                    },class:'colStyle'},
                {field: 'attrib_35', title: '销毁码',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_51', title: '销毁码图片',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='javascript:zppt(\""+value+"\");'  ><img src=\""+value+"\"  width='80px' height='80px' style='text-align: center'/></a>"
                    }},
                {field: 'attrib_26', title: '销毁时间',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {
                        return changeDateFormat1(value)
                    }},
                {field: 'attrib_99', title: '链上信息',width:300, align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='/sysadmin/block/transDetail/"+value+"'  target='_blank' >链上信息</a>"
                    }},


            ],

            // bootstrap-table-treegrid.js 插件配置 -- start

            //在哪一列展开树形
            treeShowField: 'attrib_02',
            //指定父id列
            parentIdField: 'par_row_id',

            onResetView: function () {

                $tablez2.treegrid({
                    initialState: 'collapsed',// 所有节点都折叠
                    //  initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function () {
                        $tablez2.bootstrapTable('resetWidth');
                    }
                });

                //只展开树形的第一级节点
                $tablez2.treegrid('getRootNodes').treegrid('expand');

            },
            onCheck: function (row) {

                var datas = $tablez2.bootstrapTable('getData');

                // 勾选子类
                selectChilds(datas, row, "conflict_id", "par_row_id", true);

                // 勾选父类
                selectParentChecked(datas, row, "conflict_id", "par_row_id")

                // 刷新数据
                //   $tablez2.bootstrapTable('load', datas);
            },

            onUncheck: function (row) {
                var datas = $tablez2.bootstrapTable('getData');
                selectChilds(datas, row, "conflict_id", "par_row_id", false);
                //   $tablez2.bootstrapTable('load', datas);
            },
            onClickRow: function (row, $element) {
                $tablez2.bootstrapTable('uncheckAll');
                var datas = $tablez2.bootstrapTable('getData');
                row.check = true;
                //   $tablez2.bootstrapTable('load', datas);


            }

            // bootstrap-table-treetreegrid.js 插件配置 -- end
        });
    }
    function inittabl3(rid) {
        $tablez3.bootstrapTable({
            url:'/sysadmin/commodity/getyhdds',
            idField: 'conflict_id',
            dataType: 'json',
            sidePagination: "server", //服务端处理分页
            queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
            queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的

                if(null != params.multiSort && undefined != params.multiSort){
                    params.sort = params.multiSort.map(item => {
                        return item.sortName;
                    }).join(',');
                    params.order = params.multiSort.map(item => {
                        return item.sortOrder;
                    }).join(',');
                    params.multiSort = null;
                }

                return {//这里的params是table提供的
                    pageIndex: params.pageNumber,//从数据库第几条记录开始
                    pageSize: params.pageSize,//找多少条
                    row_id:rid,
                    sortName: params.sortName,
                    sortOrder: params.sortOrder,
                    sort:params.sort,
                    order:params.order
                }
            },
            responseHandler: function (res) {
                var result = {total: 0, rows: []};

                if (res.recordCount > 0) {
                    result.total = res.recordCount;
                    result.rows = res.list;
                }
                return result;
            },
            sortable: true,
            showMultiSort: true,
            pagination: 'true',  //开启分页
            paginationPreText: '上一页',
            paginationNextText: '下一页',
             singleSelect: true, //单选

            showColumns: true,
            clickToSelect: true,
            showRefresh: true,
            columns: [
                {
                    field: 'check', checkbox: true, formatter: function (value, row, index) {
                        if (row.check == true) {
                            // console.log(row.serverName);
                            //设置选中
                            return {checked: true};
                        }
                    }
                },
                {field: 'attrib_36', title: '订单号',class:'colStyle', align: 'center',sortable : true},
                {field: 'splb', title: '类别',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_05', title: '商品名称',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_12', title: '规格',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_17', title: '数量',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_33', title: '收货人',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_10', title: '收货人电话',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_13', title: '收货地（市级）',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_19', title: '详细收货地址',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_37', title: '订单日期',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }},
                {field: 'wlkx', title: '物流可信账户',class:'colStyle', align: 'center',sortable : true},
                {field: 'jxskx', title: '经销商可信账户',class:'colStyle', align: 'center',sortable : true},
                {field: 'shrkx', title: '可信账户',width:300,class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_31', title: '订单状态',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_23', title: '订单金额',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_26', title: '发货时间',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }},
                {field: 'attrib_27', title: '收货时间',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }},
                {field: 'attrib_20', title: '备注',class:'colStyle', align: 'center',sortable : true},
            ],

            // bootstrap-table-treegrid.js 插件配置 -- start

            //在哪一列展开树形
            treeShowField: 'attrib_02',
            //指定父id列
            parentIdField: 'par_row_id',

            onResetView: function () {

                $tablez3.treegrid({
                    initialState: 'collapsed',// 所有节点都折叠
                    //  initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function () {
                        $tablez3.bootstrapTable('resetWidth');
                    }
                });

                //只展开树形的第一级节点
                $tablez3.treegrid('getRootNodes').treegrid('expand');

            },
            onCheck: function (row) {

                var datas = $tablez3.bootstrapTable('getData');

                // 勾选子类
                selectChilds(datas, row, "conflict_id", "par_row_id", true);

                // 勾选父类
                selectParentChecked(datas, row, "conflict_id", "par_row_id")

                // 刷新数据
                //   $tablez2.bootstrapTable('load', datas);
            },

            onUncheck: function (row) {
                var datas = $tablez3.bootstrapTable('getData');
                selectChilds(datas, row, "conflict_id", "par_row_id", false);
                //   $tablez2.bootstrapTable('load', datas);
            },
            onClickRow: function (row, $element) {
                $tablez3.bootstrapTable('uncheckAll');
                var datas = $tablez3.bootstrapTable('getData');
                row.check = true;
                //   $tablez2.bootstrapTable('load', datas);


            }

            // bootstrap-table-treetreegrid.js 插件配置 -- end
        });
    }




    function  inittabl(){
        $table.bootstrapTable({
            url: "/sysadmin/commodity/getcommoditys",
            idField: 'conflict_id',
            dataType: 'json',


            sidePagination: "server", //服务端处理分页
            queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
            queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的
//            请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
//　　　　　　　queryParamsType = 'limit' ,返回参数必须包含limit, offset, search, sort, order
//            queryParamsType = 'undefined', 返回参数必须包含: pageSize, pageNumber, searchText, sortName, sortOrder.
//            返回false将会终止请求。

                if(null != params.multiSort && undefined != params.multiSort){
                    params.sort = params.multiSort.map(item => {
                        return item.sortName;
                    }).join(',');
                    params.order = params.multiSort.map(item => {
                        return item.sortOrder;
                    }).join(',');
                    params.multiSort = null;
                }




                $tablez1.bootstrapTable('destroy');  // 销毁原表格
                $tablez2.bootstrapTable('destroy');  // 销毁原表格
                $tablez3.bootstrapTable('destroy');  // 销毁原表格

                /* inittabl1();
                 inittabl2();
                 inittabl3();
               */
                return {//这里的params是table提供的
                    pageIndex: params.pageNumber,//从数据库第几条记录开始
                    pageSize: params.pageSize,//找多少条
                    searchval: $("#searchString_id").val(), //这个就是搜索框中的内容，可以自动传到后台，搜索实现在xml中体现
                    searchvalcorid: $("#searchString_corid").val(),
                    status:$("#searchString_status").val(),
                    money:$("#searchString_money").val(),
                    pltype:$("#searchString_type").val(),
                    sortName: params.sortName,
                    sortOrder: params.sortOrder,
                    sort:params.sort,
                    order:params.order
                }
            },
            responseHandler: function (res) {

                var result = {total: 0, rows: []};

                if (res.recordCount > 0) {
                    result.total = res.recordCount;
                    result.rows = res.list;
                }

                return result;
            },
            sortable: true,
            showMultiSort: true,

            pagination: 'true',  //开启分页
            paginationPreText: '上一页',
            paginationNextText: '下一页',
             singleSelect: true, //单选

            showColumns: true,
            clickToSelect: true,
            showRefresh: true,
            columns: [
                {
                    field: 'check', checkbox: true, formatter: function (value, row, index) {

                        if (row.check == true) {

                            //设置选中

                            return {checked: true};
                        }
                    }
                },

                /* {field: 'attrib_03', title: 'tokenID',class:'colStyle'},
                 {field: 'attrib_04', title: '生产日期',class:'colStyle', formatter: function (value, row, index) {
                         return changeDateFormat(value)
                     }},*/
                {field: 'attrib_34', title: '类别',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_05', title: '商品名称',class:'colStyle', align: 'center',sortable : true},

                {field: 'attrib_12', title: '规格',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_17', title: '数量',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_19', title: '生产产地',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_20', title: '生产厂商',class:'colStyle', align: 'center',sortable : true},
                {field: 'attrib_45', title: '商品图片',class:'colStyle', align: 'center',sortable : true, formatter: function (value, row, index) {

                        return "<a href='javascript:zppt(\""+value+"\");'  ><img src=\""+value+"\"  width='80px' height='80px' style='text-align: center'/></a>"
                    }},
                /*    {field: 'attrib_06', title: '商品编码（IDCODE）',class:'colStyle'},*/
                {field: 'attrib_08', title: '是否上架',sortable : true,
                    formatter: function (value, row, index) {
                        if (value == 'Y') {

                            //设置选中
                            return "是"
                        }else if(value == 'N'){
                            return "否"
                        }
                    },class:'colStyle', align: 'center'},
                {field: 'attrib_23', title: '价格（元）',class:'colStyle',sortable : true, align: 'center'},
                {
                    field: 'conflict_id', title: '可信凭证生成', class: 'colStyle', align: 'center', formatter: function (value, row, index) {

                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xl " href="#" onclick="sc(\'' + value + '\',\'' + row.attrib_08 + '\')"><i class="fa fa-joomla"></i>可信凭证生成</a> ');

                        return actions.join('');
                    }
                },


                /*  {field: 'attrib_32', title: '溯源记录',class:'colStyle'},*/
                /*{field: 'attrib_41', title: '产品归属',class:'colStyle'},
                {field: 'attrib_44', title: '分类标签',class:'colStyle'},

                        {field: 'attrib_13', title: 'TID',class:'colStyle'},
                {field: 'attrib_17', title: '库存数量',class:'colStyle'},
                {field: 'attrib_43', title: '分类编码',class:'colStyle'},


                {field: 'attrib_38', title: '标签编码',class:'colStyle'},
                {field: 'attrib_39', title: '标签数据',class:'colStyle'},
                {field: 'attrib_36', title: '二维码',class:'colStyle'},



                {field: 'attrib_17', title: '库存数量',class:'colStyle'},


                */

            ],

            // bootstrap-table-treegrid.js 插件配置 -- start

            //在哪一列展开树形
            treeShowField: 'eim_source',
            //指定父id列
            parentIdField: 'par_row_id',

            onResetView: function () {

                $table.treegrid({
                    //initialState: 'collapsed',// 所有节点都折叠
                    initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function () {
                        $table.bootstrapTable('resetWidth');
                    }
                });

                //只展开树形的第一级节点
                $table.treegrid('getRootNodes').treegrid('expand');

            },
            onCheck: function (row,$element) {

                var datas = $table.bootstrapTable('getData');

                // 勾选子类
                selectChilds(datas, row, "conflict_id", "par_row_id", true);

                // 勾选父类
                selectParentChecked(datas, row, "conflict_id", "par_row_id");

                $('.changeColor').removeClass('changeColor');
                $tablez1.bootstrapTable('destroy');  // 销毁原表格
                $tablez2.bootstrapTable('destroy');  // 销毁原表格
                $tablez3.bootstrapTable('destroy');  // 销毁原表格

                inittabl1(row.row_id);
                inittabl2(row.row_id);
                inittabl3(row.row_id);


            },
            onUncheck: function (row) {

                var datas = $table.bootstrapTable('getData');
                selectChilds(datas, row, "conflict_id", "par_row_id", false);

            },
            onClickRow:function (row,$element) {
                $table.bootstrapTable('uncheckAll');
                var datas = $table.bootstrapTable('getData');
                row.check=true;




                $('.selected').removeClass('selected');

                $('.changeColor').removeClass('changeColor');

                $($element).addClass('changeColor');
                //这个就是搜索框中的内容，可以自动传到后台，搜索实现在xml中体现
                $tablez1.bootstrapTable('destroy');  // 销毁原表格
                $tablez2.bootstrapTable('destroy');  // 销毁原表格
                $tablez3.bootstrapTable('destroy');  // 销毁原表格

                inittabl1(row.row_id);
                inittabl2(row.row_id);
                inittabl3(row.row_id);

            }

            // bootstrap-table-treetreegrid.js 插件配置 -- end
        });
    }
    $(document).ready(function(){
        formValidator($("#contactform"));
        formValidator1($("#contactform1"));
        formValidator2($("#contactformz"));
        formValidator2_e($("#contactformz_e"));
        formValidator3($("#contactformz3"));

        formValidatorimp($("#contactformimp"));
        __bindRdetailformuploadinit();
        inittabl();
        /*  inittabl1();
          inittabl2();
          inittabl3();
        */
        hiddenfind();
    });
});




/*
$table.on('click-row.bs.table', function (e,row,$element) {
    $('.changeColor').removeClass('changeColor');
    $($element).addClass('changeColor');

});
*/


/**
 * 选中父项时，同时选中子项
 * @param datas 所有的数据
 * @param row 当前数据
 * @param id id 字段名
 * @param pid 父id字段名
 */
function selectChilds(datas, row, id, pid, checked) {
    for (var i in datas) {
        if (datas[i][pid] == row[id]) {

            datas[i].check = checked;
            selectChilds(datas, datas[i], id, pid, checked);
        }
        ;
    }
}


/**
 * 选中父项时，同时选中子项
 * @param datas 所有的数据
 * @param row 当前数据
 * @param id id 字段名
 * @param pid 父id字段名
 */


function selectParentChecked(datas, row, id, pid) {
    for (var i in datas) {
        if (datas[i][id] == row[pid]) {
            datas[i].check = true;
            selectParentChecked(datas, datas[i], id, pid);
        }
        ;
    }
}

function test() {
    var selRows = $table.bootstrapTable("getSelections");
    if (selRows.length == 0) {
        alert("请至少选择一行");
        return;
    }

    var postData = "";
    $.each(selRows, function (i) {
        postData += this.id;
        if (i < selRows.length - 1) {
            postData += "， ";
        }
    });
    alert("你选中行的 id 为：" + postData);

}



$('#myTab a').click(function (e) {
    e.preventDefault();
    $(this).tab('show');
})
